package com.fa.wisdom.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;


import androidx.appcompat.app.AppCompatActivity;

import com.fa.wisdom.R;
import com.fa.wisdom.base.Constant;
import com.fa.wisdom.utils.SpUtils;

import java.lang.ref.WeakReference;

/**
 * 欢迎页
 */
public class WelActivity extends AppCompatActivity {

    private static final String TAG = "WelActivity";
    //定义需要申请的相关权限

    private MyHandler myHandler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wel);
        myHandler = new MyHandler(this);
        //获取系统参数
        //获取广告页信息
        //获取权限
        myHandler.sendEmptyMessageDelayed(0, 3000);
    }

    //切换线上和测试  服务


    //获取系统参数

    /**
     * 获取广告页信息
     */


    /**
     * 获取相关权限
     */



    //静态内部类handler，防止内存泄漏
    private static class MyHandler extends Handler {

        private WeakReference<WelActivity> mActivity;

        private MyHandler(WelActivity activity) {
            mActivity = new WeakReference<>(activity);
        }

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Activity act = mActivity.get();
            String token= SpUtils.getInstance().decodeString(Constant.TOKEN,"");
            if (act != null) {
                if (!TextUtils.isEmpty(token)){
                    act.startActivity(new Intent(act, MainActivity.class));
                }else {
                    act.startActivity(new Intent(act, LoginActivity.class));
                }
                act.finish();
            }
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        myHandler.removeCallbacksAndMessages(null);
    }
}
